<?php

// [ 获取PK10计划详情 ]
// GET pk10.plan
// http://sg.51hub.cn/api?pk10.plan
// http://sg.io/api?pk10.plan&no=657680
// http://sg.io/api?pk10.plan

namespace app\api\resource\pk10;
use think\Db;
use think\facade\Validate;
use app\common\lib\Pk10Plan as Pk10PlanLib;

class Plan
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['member'];
    // 描述
    public $_description = '获取PK10计划详情';
    // 参数
    public $_param  = [
        'no' => '期号,可选,不传获取最新的计划详情',
    ];

    public function run(&$request)
    {
        $no = $request->param('no/d',0);

        if (0 == $no) {
            $ret = Db::name('plan')->order('no DESC')->find();
        } else {
            if ( !Validate::regex($no,'/^\d{6}$/') ) return [422,'期号格式不正确'];
            $ret = Db::name('plan')->where('no',$no)->find();
        }

        if ( !is_null($ret) ) {
            $ret['v1_hash'] = explode(',',$ret['v1_hash']);
            $ret['v2_hash'] = explode(',',$ret['v2_hash']);
            $ret['v3_hash'] = explode(',',$ret['v3_hash']);
            $ret['v4_hash'] = explode(',',$ret['v4_hash']);
            $ret['v5_hash'] = explode(',',$ret['v5_hash']);
        }

        return [200,$ret];
    }
}
